package net.skyedu.service;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLDecoder;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.skyedu.bean.SysOutline;
import net.skyedu.dao.DaoSupport;

public class ModifyOutline extends HttpServlet{
	private static final long serialVersionUID = 1L;

	public ModifyOutline() {
		super();
	}

	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		doPost(request,response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=utf-8");
		String id = request.getParameter("id");
		String type=request.getParameter("type");
		int claNum = Integer.parseInt(request.getParameter("claNum"));
		String claContent = request.getParameter("claContent");
		if(claContent != null && !"".equals(claContent)){
			claContent=URLDecoder.decode(claContent,"UTF-8");
		}
		if(type != null && !"".equals(type)){
			type=URLDecoder.decode(type,"UTF-8");
		}
		String teaAims = request.getParameter("teaAims");
		if(teaAims != null && !"".equals(teaAims)){
			teaAims=URLDecoder.decode(teaAims,"UTF-8");
		}
		String knowledge = request.getParameter("knowledge");
		if(knowledge != null && !"".equals(knowledge)){
			knowledge=URLDecoder.decode(knowledge,"UTF-8");
		}
		String difficulty = request.getParameter("difficulty"); //难易程度
		DaoSupport ds = new DaoSupport();
		//int count = ds.searchclaCount(Integer.parseInt(id));
		int flag = 1;
//		if(count < claNum){
//			count += 1;
			SysOutline sc = new SysOutline();
			sc.setOutCouId(Integer.parseInt(id));
			sc.setClaContent(claContent);
			sc.setTeaAims(teaAims);
			sc.setKnowledge(knowledge);
			sc.setDifficulty(Integer.parseInt(difficulty));
			sc.setClaCount(claNum);
			int num=ds.updateOutline(sc);
		 PrintWriter out = response.getWriter();
		 StringBuffer jsonAttr = new StringBuffer("[{");
		 jsonAttr.append("\"count\":\""+ds.searchclaCount(Integer.parseInt(id))+"\",");
		 jsonAttr.append("\"flag\":\""+flag+"\"");
		 jsonAttr.append("}]");
		 out.print(jsonAttr);
		 out.flush();
		 out.close();
	}

	public void init() throws ServletException {}
}
